﻿package  com.devilcat.ws{
	import com.devilcat.ws.Basicws;
	import com.worlize.websocket.*;
	import com.devilcat.dt.Gamedt;
	import com.devilcat.dt.Pokemondt;
	import com.devilcat.dt.Itemdt;
	
	public class UserItemws extends Basicws{
		var mUid:int;
		public function UserItemws(uid:int) {
			super("iw-protocol");
			mUid=uid;
		}
		override function handleWebSocketOpen(event:WebSocketEvent):void
		{
			var pack:Object = new Object();
			pack.uid=mUid;
			pack.action="loaduseritem";
			var myJson:String = JSONString(pack);
			websocket.sendUTF(myJson);
		}
		override function handleWebSocketMessage(event:WebSocketEvent):void
		{
			if (event.message.type === WebSocketMessage.TYPE_UTF8)
			{	
				Gamedt.Player.itemList = new Array();
				var itemList:Array = new Array();
				try{
					itemList =	JSONObject(event.message.utf8Data);
					for (var i= 0; i<itemList.length;i++){
						Gamedt.Player.itemList[i]=new Itemdt()
						Gamedt.Player.itemList[i].setPersonal(itemList[i]);
					}
				}catch(error:Error){}
				var lupl:UserEventws = new UserEventws(Gamedt.Player.uid);			
			}
			closeConnect();
		}

	}
	
}
